// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#ifndef CFM_OBSERVER_H_
#define CFM_OBSERVER_H_

#include "cfm.h"
#include "status/rot_status.h"


/**
 * Interface for notifying observers of CFM events.  Unwanted event notifications will be set to
 * null.
 */
struct cfm_observer {
	/**
	 * Notification that a new CFM has been verified and marked as pending.
	 *
	 * Arguments sent with this notification will not be null.
	 *
	 * @param observer The observer being notified.
	 * @param pending The CFM that passed verification and is pending.
	 */
	void (*on_cfm_verified) (struct cfm_observer *observer, struct cfm *pending);

	/**
	 * Notification that a new CFM has been made the active CFM.
	 *
	 * Arguments sent with this notification will not be null.
	 *
	 * @param observer The observer being notified.
	 * @param active The CFM that was activated.
	 */
	void (*on_cfm_activated) (struct cfm_observer *observer, struct cfm *active);

	/**
	 * Notification that the active CFM has been erased.
	 *
	 * @param observer The observer being notified.
	 */
	void (*on_clear_active) (struct cfm_observer *observer);
};


#define	CFM_OBSERVER_ERROR(code)		ROT_ERROR (ROT_MODULE_CFM_OBSERVER, code)

/**
 * Error codes that can be generated by a CFM observer.
 */
enum {
	CFM_OBSERVER_INVALID_ARGUMENT = CFM_OBSERVER_ERROR (0x00),				/**< Input parameter is null or not valid. */
	CFM_OBSERVER_NO_MEMORY = CFM_OBSERVER_ERROR (0x01),						/**< Memory allocation failed. */
	CFM_OBSERVER_MEASUREMENTS_NOT_UNIQUE = CFM_OBSERVER_ERROR (0x02),		/**< Measurement IDs are not unique */
};


#endif /* CFM_OBSERVER_H_ */
